/*
 * @Author: early-autumn
 * @Date: 2020-05-06 15:16:13
 * @LastEditors: early-autumn
 * @LastEditTime: 2020-05-27 19:44:35
 */
import dayjs from 'dayjs'

export { dayjs }

/***
 * 获得扎帐的时间
 */
export function getDebitTime() {
  return [
    dayjs()
      .startOf('day')
      .subtract(1, 'day')
      .hour('16')
      .minute('00')
      .second('00'),
    dayjs().endOf('day').hour('16').minute('00').second('00'),
  ]
}

/***
 * 获得今日起止时间
 */
export function getTodayStartWithEnd(date) {
  const day = dayjs(date)

  return [day.startOf('day'), day.endOf('day')]
}

/***
 * 获得昨日起止时间
 */
export function getYesterdayStartWithEnd(date) {
  const day = dayjs(date).subtract(1, 'day')

  return [day.startOf('day'), day.endOf('day')]
}

/**
 * 获取明日起止日期
 */
export function getTomorrowStartWithEnd(date) {
  const day = dayjs(date).add(1, 'day')

  return [day.startOf('day'), day.endOf('day')]
}

/**
 * 获取本周起止日期
 */
export function getThisWeekStartWithEnd(date) {
  const week = dayjs(date)

  return [week.startOf('week').add(1, 'day'), week.endOf('week').add(1, 'day')]
}

/**
 * 获取上周起止日期
 */
export function getLastWeekStartWithEnd(date) {
  const week = dayjs(date).subtract(1, 'week')

  return [week.startOf('week').add(1, 'day'), week.endOf('week').add(1, 'day')]
}

/**
 * 获取下周起止日期
 */
export function getNextWeekStartWithEnd(date) {
  const week = dayjs(date).add(1, 'week')

  return [week.startOf('week').add(1, 'day'), week.endOf('week').add(1, 'day')]
}

/**
 * 获取本月起止日期
 */
export function getThisMonthStartWithEnd(date) {
  const month = dayjs(date)

  return [month.startOf('month'), month.endOf('month')]
}

/**
 * 获取上月起止日期
 */
export function getLastMonthStartWithEnd(date) {
  const month = dayjs(date).subtract(1, 'month')

  return [month.startOf('month'), month.endOf('month')]
}

export function getSettleAccounts([start, end]) {
  return [dayjs(start).add(16, 'hour'), dayjs(end).add(16, 'hour')]
}

/**
 * 获取起止时间集合
 */
export function getStartWithEndDateMap() {
  const todayStartWithEnd = getTodayStartWithEnd()
  const yesterdayStartWithEnd = getYesterdayStartWithEnd()
  const tomorrowStartWithEnd = getTomorrowStartWithEnd()
  const thisWeekStartWithEnd = getThisWeekStartWithEnd()
  const thisMonthStartWithEnd = getThisMonthStartWithEnd()
  const lastMonthStartWithEnd = getLastMonthStartWithEnd()

  return {
    昨日: yesterdayStartWithEnd,
    今日: todayStartWithEnd,
    明日: tomorrowStartWithEnd,
    本周: thisWeekStartWithEnd,
    本月: thisMonthStartWithEnd,
    同比: lastMonthStartWithEnd,
  }
}
